package com.k8.common.aop.internal.interceptor;

import com.k8.common.aop.internal.invocation.MethodInvocation;

public class ExposeInvocationInterceptor implements MethodInterceptor{
    private final static ThreadLocal<MethodInvocation> localInvocation=new ThreadLocal<>();
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        if (localInvocation.get()==null){
            localInvocation.set(invocation);
        }
        return invocation.proceed();
    }

    public ExposeInvocationInterceptor() {

    }

    protected static MethodInvocation currentMethodInvocation(){
        MethodInvocation methodInvocation = localInvocation.get();
        if (methodInvocation==null){
            throw new IllegalStateException("localInvocation is null");
        }
        return methodInvocation;
    }
}
